package com.aglow.bluetoothspeaker.main.ui.dialog;

import android.animation.ObjectAnimator;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import com.aglow.bluetoothspeaker.R;
import com.facebook.stetho.common.LogUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Author: chufeng
 * Email: 392044178@qq.com
 * Date: 2018/9/13 14:22
 * Depict: 藍牙信息dialog
 */
public class BluetoothInfoDialog extends Dialog {

    @BindView(R.id.iv_logo)
    ImageView ivLogo;
    @BindView(R.id.tv_bluetooth_info)
    TextView tvBluetoothInfo;
    private ObjectAnimator rotation;


    public BluetoothInfoDialog(@NonNull Context context) {
        this(context, R.style.LoadingDialogStyle);
    }

    public BluetoothInfoDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

//    private static int getDefaultDialogTheme(Context context) {
//        TypedValue outValue = new TypedValue();
//        context.getTheme().resolveAttribute(R.attr.alertDialogTheme, outValue, true);
//
//        return outValue.resourceId;
//    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_prompt);
        ButterKnife.bind(this);
        WindowManager.LayoutParams params = getWindow().getAttributes();

        params.width = WindowManager.LayoutParams.WRAP_CONTENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(params);

    }


    public void setLogoDrawable(int res) {
        ivLogo.setImageResource(res);
    }

    public void setTvBluetoothInfo(String info) {
        tvBluetoothInfo.setText(info);
    }

    /**
     * 开启旋转
     **/
    public void startLogoAnimat() {
        rotation = ObjectAnimator.ofFloat(ivLogo, "Rotation", 0f, 360f);
        rotation.setDuration(3500);
        rotation.setRepeatCount(ObjectAnimator.INFINITE);
        rotation.setRepeatMode(ObjectAnimator.RESTART);
        rotation.setInterpolator(new LinearInterpolator());
        rotation.start();
    }

    public void stopLogoAnimat() {
        if (rotation!=null&&rotation.isRunning()){
            rotation.removeAllUpdateListeners();
            rotation.cancel();
            rotation = null;
        }
    }


    @OnClick({R.id.iv_logo, R.id.tv_bluetooth_info})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_logo:
                break;
            case R.id.tv_bluetooth_info:
                break;
        }
    }
}
